package com.gomyb.oss;

import lombok.Getter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author <a href="mailto:hellohesir@gmail.com">Mr_He</a>
 * 2019/4/19 13:31
 */
@Configuration
@Component
@Getter
public class FileConfiguration implements WebMvcConfigurer {

    // local storage
    @Value("${file.uploadFolder}")
    private String uploadFolder;

    // mapping storage
    @Value("${file.staticAccessPath}")
    private String staticAccessPath;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler(staticAccessPath).addResourceLocations("file:" + uploadFolder);
    }

}
